package com.example.myfragmenttest;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

public class Fragment1 extends Fragment {
	
	OnFragListener mCallBack;
	
	public interface OnFragListener{
		public void onButtonClick();
		public void onButOther() ;
		public void onButOther3() ;
			
		
	}

	@Override
	public void onAttach(Activity activity) {
		// TODO Auto-generated method stub
		super.onAttach(activity);
		mCallBack=(OnFragListener) activity;
		try {
			
		} catch (ClassCastException e) {
			// TODO: handle exception
			throw new ClassCastException(e.toString()+">>"+activity.toString()+"must implement ");
		}
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		return inflater.inflate(R.layout.fragment1, container, false);
	}

	@Override
	public void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		Button button=(Button) getActivity().findViewById(R.id.btnGetText);
		button.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				System.out.println("onButtonClick"+this.getClass().toString());
				mCallBack.onButtonClick();
				
			}
		});
		Button button2=(Button) getActivity().findViewById(R.id.button1);
		button2.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				mCallBack.onButOther();
				
			}
		});
		Button button3=(Button) getActivity().findViewById(R.id.button2);
		button3.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				mCallBack.onButOther3();
				
			}
		});

		
	}
	
	
}
